package org.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//删除操作
public class Jdbc_Teacher_CRUD_Delete {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/mysqlbase";
        String user = "root";
        String password = "1234";
        String sql = "DELETE FROM teacher WHERE id =?";
        try (Connection conn = DriverManager.getConnection(url, user, password)){
            conn.setAutoCommit(false);
            try (PreparedStatement preparedStatement = conn.prepareStatement(sql)){
                preparedStatement.setInt(1, 1);
                preparedStatement.executeUpdate();
                conn.commit();
            }catch (SQLException e){
                conn.rollback();
                e.printStackTrace();
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
